#include "ParticleBattery.h"

#include "ParticleContext.h"
#include "DescriptorParticle.h"

#include "ParticleSimple.h"

using namespace ParticleEngine; 

const DescriptorParticle ParticleBattery::Descriptor
(
	"Battery", 
	[](ParticleContext& NewContext) { return new ParticleBattery(NewContext); }
); 

ParticleBattery::ParticleBattery(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleBattery::Descriptor),
Heat(1.0f),
Electricity(1.0f),
Charge(30.f)
{
	Adhesions = new PropertyAdhesions(0.08f);
	Adhesions->ParticleCast = this;
}
ParticleBattery::~ParticleBattery()
{
}

void ParticleBattery::Sole()//einzelne aktualisierzung
{
	this->SoleStandard();

	const float FlowRate = 0.01f;
	if (this->Electricity.Volume < 1.f - FlowRate)
		if (this->Charge > FlowRate)
		{
			this->Charge -= FlowRate;
			this->Electricity.Volume += FlowRate;
		}

	if (this->Heat.Volume > 0.5 || this->Heat.ContentAdjust > 0.01f)
	{
		this->Context.ToRemoveArray.Add(this);

		ParticleBase* NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos;
		NewParticle->Velocity = this->Velocity;
		this->Context.ToAddArray.Add(NewParticle);
	}

	Heat.Sole();
	Electricity.Sole();
}
void ParticleBattery::InteractionIndividual(ParticleBase*const Other, Vec<2, float>& Space, const float& DistanceSquared)
{
	this->InteractionKinetics(Other, Space, DistanceSquared);

	Heat.Interaction(Other->HasHeat());
	Electricity.Interaction(Other->HasElectricity());
}

ColorRGBA<unsigned char> ParticleBattery::GetColor()
{
	return ColorRGBA<unsigned char> (200, 200, 20, 255);
}

void ParticleBattery::SaveIndividual(std::ofstream& Strm)
{
	Heat.Save(Strm);
}
void ParticleBattery::LoadIndividual(std::ifstream& Strm)
{
	Heat.Load(Strm);
}


